package cn.portx.frame.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.bstek.bdf3.saas.SaasUtils;
import com.bstek.bdf3.saas.domain.Organization;

import cn.portx.ICallback;

@Component
public class OrganizationDBHelper {

	@Autowired
	private OrganizationDBServiceImpl organizationDBServiceImpl;

	public <T> T doDb(String orgId, boolean ransactionReadOnly, ICallback<T, Void> callback) {
		Organization org = new Organization();
		org.setId(orgId);
		return this.doDb(org, ransactionReadOnly, callback);
	}

	public <T> T doDb(Organization org, boolean ransactionReadOnly, ICallback<T, Void> callback) {
		return SaasUtils.doNonQuery(() -> {
			return callback.execute(null);
		});
//		SaasUtils.pushSecurityContext(org);
//		try {
//			if (ransactionReadOnly) {
//				return this.organizationDBServiceImpl.doDbReadOnly(org, callback);
//			}
//			return this.organizationDBServiceImpl.doDb(org, callback);
//		} finally {
//			SaasUtils.popSecurityContext();
//		}
	}
}
